package com.cf.r952_ak;

import java.io.*;

public class g {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(System.out);
        in.nextToken(); int t = (int) in.nval;
        while (t-- > 0) {
            in.nextToken(); long l = (long) in.nval;
            in.nextToken(); long r = (long) in.nval;
            in.nextToken(); long k = (long) in.nval;

            long m = 9 / k;
            if (m == 0) {
                out.println(0);
                continue;
            }
            long a = m;
            long b = m + 1;

            long p1 = modPow(b, r);
            long p2 = modPow(b, l);

            long x = (p1 - p2 + mod) % mod;
            long y = modPow(b - 1, mod - 2);
            long ans = a % mod * x % mod * y % mod;
            out.println(ans);
        }
        out.flush();
        out.close();
        br.close();
    }

    static final int mod = 1000000007;

    public static long modPow(long a, long e) {
        long s = 1;
        while (e > 0) {
            if ((e & 1) == 1) s = (s * a) % mod;
            a = (a * a) % mod;
            e >>= 1;
        }
        return s;
    }
}
